﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace CleanToolkit.FieldsExctration
{
    public class ContentTypeFieldsExtractor : FieldsExtractor
    {

        /// <summary>
        /// Création d'une déclaration de SPField de ContentType sur la base de la déclaration du SPField
        /// </summary>
        /// <param name="xSchemaField"></param>
        /// <returns></returns>
        protected override XElement GetFieldDef(XElement xSchemaField)
        {
            XElement result = null;
            //--------------------------------------------------

            // On copie le SPField fourni, et on en supprime
            //      * Group
            //      * StaticName
            result = new XElement("FieldRef");

            result.SetAttributeValue("ID", xSchemaField.Attribute("ID").Value);
            result.SetAttributeValue("Name", xSchemaField.Attribute("Name").Value);
            result.SetAttributeValue("DisplayName", xSchemaField.Attribute("DisplayName") == null ? string.Empty : xSchemaField.Attribute("DisplayName").Value);
            //result.SetAttributeValue("Required", xSchemaField.Attribute("Required") == null ? "FALSE" : xSchemaField.Attribute("Required").Value);

            //--------------------------------------------------
            return result;
        }
    }
}
